<template>
	<view>
		<view class="iconfont b_icon" :style="flag_capture ? 'opacity: 0;':''" @click="backFun">&#xe8c8;</view>
		<view class="bg_box">
			<view class="bg01">
				<image :src="Cfg.Setting.img+'bg04.png'"></image>
			</view>
			<view class="content">
				<view class="bg02">
					<image src="../../static/bg05.png" mode="heightFix"></image>
				</view>
				<view class="text_box">
					<view class="title">您的邀请码为</view>
					<view class="num">{{user.tj_code}}</view>
					<view class="copy" @tap="paste()" :style="flag_capture ? 'opacity: 0;':''">复制</view>
					<view class="ewm">
					<tki-qrcode
						v-if="true"
						cid="qrcode"
						ref="qrcode"
						:val="user.ewm"
						:size="250"
						:onval="true"
						:loadMake="true"
						:usingComponents="true"
						@result="qrR"						
					/>
					</view>
				<!-- 	<view class="copy2" :style="flag_capture ? 'opacity: 0;':''" @tap="paste1()">复制链接</view> -->
					<view class="keep" :style="flag_capture ? 'opacity: 0;':''">
						<!-- <view class="k_btn" @tap='shareToFriend'>保存二维码到手机</view> -->
						<view class="k_btn" @tap='capturestar'>保存二维码到手机</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue';
		import Cfg from '../../common/config.js';
	export default {
		components: {
			tkiQrcode
		},
		data() {
			return {
				user:'',
				flag_capture:false,
			}
		},
		onLoad() {
			
				let me = this;
				me.Net._get('fx',null,res=>{
					console.log(res)
					me.user = res.data;
					//me.user.ewm= this.user.url
				});
			
		},
		 
		onShareAppMessage(res) {
		            console.log("分享", res)
		      
		            return{
		                title: "汉家承",
		                path: "/pages/index/index?id="+this.user.tj_code,
		                imageUrl: this.user.ewm,
		                desc: "",
		                content: "",
		                success(res){
		                    uni.showToast({
		                        title:'分享成功'
		                    })
		                },
		                fail(res){
		                    uni.showToast({
		                        title:'分享失败',
		                        icon:'none'
		                    })
		                }
		            }
		        },
				onShareTimeline(res) {
				            console.log("分享", res)
				      
				            return{
				                title: "汉家承",
				                path: "/pages/index/index?id="+this.user.tj_code,
				                imageUrl: this.user.ewm,
				                desc: " ",
				                content: " ",
				                success(res){
				                    uni.showToast({
				                        title:'分享成功'
				                    })
				                },
				                fail(res){
				                    uni.showToast({
				                        title:'分享失败',
				                        icon:'none'
				                    })
				                }
				            }
				        },
		methods: {
			qrR(res) {
				this.src = res;
				//console.log(res)
			},
			shareToFriend() {
			   let path = []
			   path.push(this.user.ewm)
			   wx.previewImage({
			     urls: path,
			   })
			 },
			paste() {
				var value = this.user.tj_code;
				console.log(value)
				uni.setClipboardData({
					data: value
				});
			},
			paste1() {
				var value = this.user.ewm;
				console.log(value)
				uni.setClipboardData({
					data: value
				});
			},
			saveImg(e){
			   let url = e.currentTarget.dataset.url;
			   wx.saveImageToPhotosAlbum({
			     filePath:url,
			     success(res) { 
			      console.log(res);
			     },
			     fail(res){
			      console.log(res);
			     }
			    })
			 },
			 capturestar() {
			 	var that = this;
				this.flag_capture = true;
				setTimeout(function(){that.capture()},1000);
			 },
			 capture() {
			 	var that = this;
			 	var pages = getCurrentPages();
			 	var page = pages[pages.length - 1];
			 	console.log('当前页' + pages.length - 1);
			 	var bitmap = null;
			 	var currentWebview = page.$getAppWebview();
			 	// var currentWebview = plus.webview.currentWebview('.bg_img');
			 	// var currentWebview = this.$scope.$getAppWebview('bg_img');
			 	// var currentWebview = this.$mp.page.$getAppWebview('.bg_img');
			 	bitmap = new plus.nativeObj.Bitmap('amway_img');
			 	// 将webview内容绘制到Bitmap对象中
			 
			 	currentWebview.draw(
			 		bitmap,
			 		function() {
			 			console.log('截屏绘制图片成功');
			 			bitmap.save(
			 				'_doc/a.jpg',
			 				{},
			 				function(i) {
			 					console.log('保存图片成功：' + JSON.stringify(i));
			 					uni.saveImageToPhotosAlbum({
			 						filePath: i.target,
			 						success: function() {
			 							bitmap.clear(); //销毁Bitmap图片
			 							uni.showToast({
			 								title: '保存图片成功',
			 								mask: false,
			 								duration: 1500
			 							});
			 							that.flag_capture = false;
			 						}
			 					});
			 				},
			 				function(e) {
			 					console.log('保存图片失败：' + JSON.stringify(e));
			 					that.heard = true;
								that.flag_capture = false;
			 				}
			 			);
			 		},
			 		function(e) {
			 			console.log('截屏绘制图片失败：' + JSON.stringify(e));
			 			that.heard = true;
						that.flag_capture = false;
			 		}
			 	);
			 	//currentWebview.append(amway_bit);
			 },
			 backFun(){
				 uni.navigateBack();
			 }
		}
	}
</script>

<style>
page{
	
}
.b_icon{
	font-size: 6vw;
	position: fixed;
	padding: calc(var(--status-bar-height) + 3vh) 4% 20rpx;
	color: #FFFFFF;
	z-index: 99;
}
.bg_box{
	width: 100%;
	height: 100vh;
	position: relative;
}

.bg_box .bg01{
	width: 100%;
	height: 100vh;
	position: relative;
	z-index: 9;
}

.bg_box .bg01 image{
	width: 100%;
	display: block;
	position: absolute;
	height: 100%;
}

.bg_box .content{
	width: 100%;
	position: fixed;
	height: 58vh;
	z-index: 10;
	left: 0;
	bottom: 6vh;
}

.bg_box .content .bg02{
	width: 100%;
	height: 58vh;
	display: flex;
	justify-content: center;
	position: absolute;
	left: 0;
	top: 0;
	z-index: 11;
}

.bg_box .content .bg02 image{
	height: 100%;
}

.bg_box .content .text_box{
	width: 100%;
	height: 100%;
	padding-top: 10vh;
	position: relative;
	z-index: 12;
	display: flex;
	flex-direction: column;
}

.bg_box .content .text_box .title{
	font-size: 5vw;
	color: #333;
	text-align: center;
}

.bg_box .content .text_box .num{
	font-size: 6vw;
	font-weight: bold;
	color: #FD3633;
	text-align: center;
	margin-top: 2vw;
}

.bg_box .content .text_box .copy{
	font-size:3.6vw;
	color: #FD3633;
	text-align: center;
	width: 12vw;
	height: 6vw;
	border: 1px solid #FD3633;
	border-radius: 6vw;
	line-height: 6vw;
	margin: 2vw auto;
}
.bg_box .content .text_box .copy2{
	font-size:3.6vw;
	color: #FD3633;
	text-align: center;
	width: 100%;
	height: 6vw;
	line-height: 6vw;
	margin: 2vw auto;
	text-decoration: underline;
}

.bg_box .content .text_box .ewm{
	width: 35vw;
	height: 35vw;
	margin: 0 auto;
	background-color: #EBDACA;
	padding: 1vw;
	text-align: center;
}

.bg_box .content .text_box .ewm image{
	width: 100%;
	height: 100%;
}

.confirm02{
	width: 50%;
	margin-top: 6vw;
}


.bg_box .content .text_box .keep{
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
}
.bg_box .content .text_box .keep .k_btn{
	font-size: 4vw;
	color: #FF455C;
	text-align: center;
	background: #FFDF4E;
	border-radius: 50rpx;
	height: 80rpx;
	width: 50%;
	line-height: 80rpx;
}
</style>
